<template>
  <div id="app" class="container">
    <div class="header">
      <router-link :to="{ name: 'Home' }" class="home-link" v-show="isHome"
        ><i class="fa fa-home"></i
      ></router-link>
      小乖-shopping
    </div>
    <router-view class="content"></router-view>
    <ul class="footer" v-show="isShowFooter">
      <li :class="currentIndex == 0 ? 'active' : ''" @click="navTo('Home', 0)">
        <i class="fa fa-home"></i>
        <span>首页</span>
      </li>
      <li :class="currentIndex == 1 ? 'active' : ''" @click="navTo('Hot', 1)">
        <i class="fa fa-fire"></i>
        <span>热卖</span>
      </li>
      <li
        :class="currentIndex == 2 ? 'active' : ''"
        style="position:relative;"
        @click="navTo('Cart', 2)"
      >
        <span class="dot" v-show="$store.state.cartCount > 0">{{
          $store.state.cartCount
        }}</span>
        <i class="fa fa-shopping-cart"></i>
        <span>购物车</span>
      </li>
      <li :class="currentIndex == 3 ? 'active' : ''" @click="navTo('User', 3)">
        <i class="fa fa-user"></i>
        <span>我的</span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentIndex: 0,
      isShowFooter: true,
      isHome: true
    }
  },
  watch: {
    $route(v) {
      if (v.meta.isShowFooter) {
        this.isShowFooter = false
      } else {
        this.isShowFooter = true
      }
      if (v.meta.isHome) {
        this.isHome = false
      } else {
        this.isHome = true
      }
    }
  },
  methods: {
    navTo(name, index) {
      this.currentIndex = index
      this.$router.push({ name: name }).catch(() => {})
    }
  }
}
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
html,
body,
#app,
.container {
  width: 100%;
  height: 100%;
}
.container {
  display: flex;
  flex-direction: column;
}
.container .header {
  height: 40px;
  text-align: center;
  background: rgb(14, 184, 184);
  line-height: 40px;
  color: rgb(0, 0, 0);
  font-weight: 900;
}
.container .content {
  flex: 1;
  overflow: auto;
}
.container .footer {
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgb(14, 184, 184);
  color: rgb(0, 0, 0);
}
ul li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
ul li i::before {
  font-size: 22px;
}
ul li span {
  font-size: 10px;
}
ul li.active {
  color: rgb(255, 255, 255);
  font-weight: 900;
}

.dot {
  background: palevioletred;
  color: white;
  width: 0.2rem;
  height: 0.2rem;
  border-radius: 50%;
  position: absolute;
  padding: 0.02rem;
  top: -10px;
  left: 16px;
  text-align: center;
}
.home-link {
  float: left;
  font-size: 22px;
  margin-left: 6px;
  color: white;
}
</style>
